package com.otitan.la.forest.system.exception.handle;

import com.otitan.la.forest.system.exception.FileException;
import com.otitan.webapp.framework.basepro.model.DataResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description: 当前类作用描述
 * @Author: xiazw
 * @CreateDate: 2020/8/4 15:40
 */
@RestControllerAdvice
@Slf4j
public class ExceptionHandle {
    @ExceptionHandler(value = {
            PersistenceException.class,
            RedisConnectionFailureException.class
    })
    public DataResult persistenceException(Exception e) {
        log.error("Exception,exception:{}", e, e);
        return DataResult.fail("网络异常");
    }

    @ExceptionHandler(value = FileException.class)
    public DataResult fileException(FileException e) {
        log.error("Exception,exception:{}", e, e);
        return DataResult.fail(e.getMessage());

    }
}